/*******************************************************************************
File: 4_other_involvement
Project: CPKIN
Purpose: This .do file cleans and analyzes data on involvement of other actors in child protection activities 
Author: Akshay Dixit
Date Created: Feb 25, 2019
Date modified: June 30, 2020
********************************************************************************/

clear all
set more off

***THIS IS THE INPUT THAT MUST BE CHANGED SPECIFIC TO THE USER***
*gl identity ""
*gl user "" 

********************************************************************************

***Creating Global File Paths***'
gl data "$user/data"
gl dof "$user/do files"
gl analysis "$user/analysis"

********************************************************************************

u "$data/endline_adult_chief_child_data.dta", clear

* Dropping child survey - these questions were not asked of children at all
drop if type_survey == "child"

* Stratification variable - Chiefdom
gl chiefdom = "bagruwa_chief barri_chief bumpeh_chief fakunya_chief gallinas_perri_chief kaiyamba_chief kamarjei_chief kori_chief kowa_chief kpaka_chief malin_chief sowa_chief"

* Control variables
gl controls = "wealth_index female age attend_school fp_visit vil_pop"

* Outcome variables

	//Family, Parents, Older Children
local family fam_med fam_study fam_needs fam_preg fam_sch fam_pnsh_hvywork fam_sev_beat fam_care ///
oldchd_med oldchd_study oldchd_needs oldchd_preg oldchd_sch oldchd_pnsh_hvywork oldchd_sev_beat oldchd_care ///
par_med par_study par_needs par_preg par_sch par_pnsh_hvywork par_sev_beat par_care 

foreach var of local family {
	replace `var' = 0 if (`var' == 4)	//Changing 4 (This problem hasn't happened in the past six months) to 0 for ease of coding
	replace `var' = 0 if (`var' == .d)	//.d is the same as 4 (This problem hasn't happened)
	replace `var' = 0 if (`var' == .c)	//.c means the respondent is unaware of the existence of this stakeholder
}	
	
egen response_family = rowtotal(fam_med fam_study fam_needs fam_preg fam_sch fam_pnsh_hvywork fam_sev_beat fam_care ///
oldchd_med oldchd_study oldchd_needs oldchd_preg oldchd_sch oldchd_pnsh_hvywork oldchd_sev_beat oldchd_care ///
par_med par_study par_needs par_preg par_sch par_pnsh_hvywork par_sev_beat par_care), missing

replace response_family = 1 if (response_family > 0 & response_family != .)

********************************************************************************
	
	//Community - Village elite, children's clubs, community members, Child Welfare Committee (CWC), religious groups, women's clubs 
local community bus_rich_med bus_rich_study bus_rich_needs bus_rich_preg bus_rich_sch bus_rich_pnsh_hvywork bus_rich_sev_beat bus_rich_care ///
chdclubs_med chdclubs_study chdclubs_needs chdclubs_preg chdclubs_sch chdclubs_pnsh_hvywork chdclubs_sev_beat chdclubs_care ///
com_med com_study com_needs com_preg com_sch com_pnsh_hvywork com_sev_beat com_care ///
cwc_med cwc_study cwc_needs cwc_preg cwc_sch cwc_pnsh_hvywork cwc_sev_beat cwc_care ///
religious_med religious_study religious_needs religious_preg religious_sch religious_pnsh_hvywork religious_sev_beat religious_care ///
wmensclubs_med wmensclubs_study wmensclubs_needs wmensclubs_preg wmensclubs_sch wmensclubs_pnsh_hvywork wmensclubs_sev_beat wmensclubs_care

foreach var of local community {
	replace `var' = 0 if (`var' == 4) 
	replace `var' = 0 if (`var' == .d) 
	replace `var' = 0 if (`var' == .c)
}

egen response_community = rowtotal(bus_rich_med bus_rich_study bus_rich_needs bus_rich_preg bus_rich_sch bus_rich_pnsh_hvywork bus_rich_sev_beat bus_rich_care ///
chdclubs_med chdclubs_study chdclubs_needs chdclubs_preg chdclubs_sch chdclubs_pnsh_hvywork chdclubs_sev_beat chdclubs_care ///
com_med com_study com_needs com_preg com_sch com_pnsh_hvywork com_sev_beat com_care ///
cwc_med cwc_study cwc_needs cwc_preg cwc_sch cwc_pnsh_hvywork cwc_sev_beat cwc_care ///
religious_med religious_study religious_needs religious_preg religious_sch religious_pnsh_hvywork religious_sev_beat religious_care ///
wmensclubs_med wmensclubs_study wmensclubs_needs wmensclubs_preg wmensclubs_sch wmensclubs_pnsh_hvywork wmensclubs_sev_beat wmensclubs_care), missing

replace response_community = 1 if (response_community > 0 & response_community != .)

********************************************************************************
	
	//Government - Local councilor, Family Support Unit (FSU), Social Development Officers (SDOs), Government Social Workers
local government councilor_med councilor_study councilor_needs councilor_preg councilor_sch councilor_pnsh_hvywork councilor_sev_beat councilor_care ///
fsu_med fsu_study fsu_needs fsu_preg fsu_sch fsu_pnsh_hvywork fsu_sev_beat fsu_care ///
sdo_med sdo_study sdo_needs sdo_preg sdo_sch sdo_pnsh_hvywork sdo_sev_beat sdo_care ///
sworker_med sworker_study sworker_needs sworker_preg sworker_sch sworker_pnsh sworker_sev_beat sworker_care

foreach var of local government {
	replace `var' = 0 if (`var' == 4) 
	replace `var' = 0 if (`var' == .d) 
	replace `var' = 0 if (`var' == .c)	
}

egen response_govt = rowtotal(councilor_med councilor_study councilor_needs councilor_preg councilor_sch councilor_pnsh_hvywork councilor_sev_beat councilor_care ///
fsu_med fsu_study fsu_needs fsu_preg fsu_sch fsu_pnsh_hvywork fsu_sev_beat fsu_care ///
sdo_med sdo_study sdo_needs sdo_preg sdo_sch sdo_pnsh_hvywork sdo_sev_beat sdo_care ///
sworker_med sworker_study sworker_needs sworker_preg sworker_sch sworker_pnsh sworker_sev_beat sworker_care), missing

replace response_govt = 1 if (response_govt > 0 & response_govt != .)

********************************************************************************

	//Chiefs - Paramount chiefs, village chiefs, Section chiefs
local chiefs pc_med pc_study pc_needs pc_preg pc_sch pc_pnsh_hvywork pc_sev_beat pc_care ///
secchief_med secchief_study secchief_needs secchief_preg secchief_sch secchief_pnsh_hvywork secchief_sev_beat secchief_care ///
vilchief_med vilchief_study vilchief_needs vilchief_preg vilchief_sch vilchief_pnsh_hvywork vilchief_sev_beat vilchief_care

foreach var of local chiefs {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}

egen response_chiefs = rowtotal(pc_med pc_study pc_needs pc_preg pc_sch pc_pnsh_hvywork pc_sev_beat pc_care ///
secchief_med secchief_study secchief_needs secchief_preg secchief_sch secchief_pnsh_hvywork secchief_sev_beat secchief_care ///
vilchief_med vilchief_study vilchief_needs vilchief_preg vilchief_sch vilchief_pnsh_hvywork vilchief_sev_beat vilchief_care), missing

replace response_chiefs = 1 if (response_chiefs > 0 & response_chiefs != .)

********************************************************************************
	
	//Teachers and SMC members
local edu smc_med smc_study smc_needs smc_preg smc_sch smc_pnsh_hvywork smc_sev_beat smc_care ///
tchr_med tchr_study tchr_needs tchr_preg tchr_sch tchr_pnsh_hvywork tchr_sev_beat tchr_care

foreach var of local edu {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}

egen response_edu = rowtotal(smc_med smc_study smc_needs smc_preg smc_sch smc_pnsh_hvywork smc_sev_beat smc_care ///
tchr_med tchr_study tchr_needs tchr_preg tchr_sch tchr_pnsh_hvywork tchr_sev_beat tchr_care), missing

replace response_edu = 1 if (response_edu > 0 & response_edu != .)

********************************************************************************
	
	//Community Health Officers
local cho cho_med cho_study cho_needs cho_preg cho_sch cho_pnsh_hvywork cho_sev_beat cho_care

foreach var of local cho {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}	

egen response_cho = rowtotal(cho_med cho_study cho_needs cho_preg cho_sch cho_pnsh_hvywork cho_sev_beat cho_care), missing

replace response_cho = 1 if (response_cho > 0 & response_cho != .)
	
********************************************************************************
	
	//NGOs
local ngos actionaid_med actionaid_study actionaid_needs actionaid_preg actionaid_sch actionaid_pnsh_hvywork actionaid_sev_beat actionaid_care ///
chdfund_med chdfund_study chdfund_needs chdfund_preg chdfund_sch chdfund_pnsh_hvywork chdfund_sev_beat chdfund_care ///
ngos_med ngos_study ngos_needs ngos_preg ngos_sch ngos_pnsh_hvywork ngos_sev_beat ngos_care ///
plan_med plan_study plan_needs plan_preg plan_sch plan_pnsh_hvywork plan_sev_beat plan_care ///
savechdrn_med savechdrn_study savechdrn_needs savechdrn_preg savechdrn_sch savechdrn_pnsh_hvywork savechdrn_sev_beat savechdrn_care ///
unicef_med unicef_study unicef_needs unicef_preg unicef_sch unicef_pnsh_hvywork unicef_sev_beat unicef_care ///
wrldvision_med wrldvision_study wrldvision_needs wrldvision_preg wrldvision_sch wrldvision_pnsh_hvywork wrldvision_sev_beat wrldvision_care

foreach var of local ngos {
	replace `var' = 0 if (`var' == 4)
	replace `var' = 0 if (`var' == .d)
	replace `var' = 0 if (`var' == .c)
}	

egen response_ngos = rowtotal(actionaid_med actionaid_study actionaid_needs actionaid_preg actionaid_sch actionaid_pnsh_hvywork actionaid_sev_beat actionaid_care ///
chdfund_med chdfund_study chdfund_needs chdfund_preg chdfund_sch chdfund_pnsh_hvywork chdfund_sev_beat chdfund_care ///
ngos_med ngos_study ngos_needs ngos_preg ngos_sch ngos_pnsh_hvywork ngos_sev_beat ngos_care ///
plan_med plan_study plan_needs plan_preg plan_sch plan_pnsh_hvywork plan_sev_beat plan_care ///
savechdrn_med savechdrn_study savechdrn_needs savechdrn_preg savechdrn_sch savechdrn_pnsh_hvywork savechdrn_sev_beat savechdrn_care ///
unicef_med unicef_study unicef_needs unicef_preg unicef_sch unicef_pnsh_hvywork unicef_sev_beat unicef_care ///
wrldvision_med wrldvision_study wrldvision_needs wrldvision_preg wrldvision_sch wrldvision_pnsh_hvywork wrldvision_sev_beat wrldvision_care), missing

replace response_ngos = 1 if (response_ngos > 0 & response_ngos != .)

********************************************************************************
	
* Label variables
lab var response_community "Community"
lab var response_govt "Government"
lab var response_chiefs "Chiefs"
lab var response_edu "Teachers and SMC members"
lab var response_cho "Community Health Officers"
lab var response_ngos "NGOs"

lab var treatment "Treatment"
lab var wealth_index "Wealth index" 
lab var female "Female"
lab var age "Age"
lab var attend_school "Ever attended school" 
lab var fp_visit "Village visited by UNICEF monitoring team"
lab var vil_pop "Village population"
lab var chief "Respondent: Chief"
lab var sms_received "CPKIN SMS received"

********************************************************************************

***ITT analysis***

cd "$analysis"

cap erase "ITT_other_involvement.xls"

local outcomes response_community response_govt response_chiefs response_edu response_cho response_ngos
foreach var of local outcomes {
	
	di "`var'" 
	
	qui sum `var' if treatment == 0
	local control_mean = (r(mean))
	local rounded = round(`control_mean', 0.01)
	
	qui reg `var' treatment $chiefdom $controls chief, vce(cluster village_id1)
	
	local p = 2 * (1-normal(abs(_b[treatment]/_se[treatment])))
	local p_round = round(`p', 0.001)
	
	outreg2 using "ITT_other_involvement.xls", append label keep(treatment wealth_index female age attend_school fp_visit vil_pop chief) ///
	addtext(Naive p-value, "`p_round'", Control group mean, "`rounded'") ///
	addnote("Standard errors clustered at the village-level. Specifications include binary variables for randomization strata.")
	
}

cap erase "ITT_other_involvement.txt"

********************************************************************************

***TOT analysis with sms_received as instrument***

cap erase "TOT_other_involvement.xls"
	
local outcomes response_community response_govt response_chiefs response_edu response_cho response_ngos
foreach var of local outcomes {

	di "`var'"

	qui sum `var' if treatment == 0
	local control_mean = (r(mean))
	local rounded = round(`control_mean', 0.01)
	
	qui ivregress 2sls `var' $chiefdom $controls chief (sms_received = treatment), vce(cluster village_id1)
	
	local p = 2 * (1-normal(abs(_b[sms_received]/_se[sms_received])))
	local p_round = round(`p', 0.001)
	
	outreg2 using "TOT_other_involvement.xls", append label keep(sms_received wealth_index female age attend_school fp_visit vil_pop chief) ///
	addtext(Naive p-value, "`p_round'", Control group mean, "`rounded'") ///
	addnote("Standard errors clustered at the village-level. Specifications include binary variables for randomization strata.") 
	
}

cap erase "TOT_other_involvement.txt"

********************************************************************************

clear

